package leetcode.array;

/**
 * @Description: https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/
 * @Author Ammar
 * @Create 2023/9/13 18:38
 */
public class _153_寻找旋转排序数组中的最小值 {
    public int findMin(int[] nums) {
        if (nums.length == 1||nums[0] < nums[nums.length -1]) {
            return nums[0];
        }
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            int mid = left + ((right - left) >> 1);
            if(nums[mid] > nums[right]) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return nums[left];
    }
}
